package com.liyujie.networkrequest.utils.message_queue;

import com.blankj.utilcode.util.LogUtils;

public class LogTask extends BaseTask {
    String name;

    public LogTask(String name) {
        this.name = name;
    }

    //执行任务方法，在这里实现你的任务具体内容
    @Override
    public void doTask() {
        super.doTask();
        LogUtils.i("LogTask", "--doTask-" + name);

        //如果这个Task的执行时间是不确定的，比如上传图片，那么在上传成功后需要手动调用
        //unLockBlock方法解除阻塞，例如：
        uploadImage(new UploadListener() {
            @Override
            public void onSuccess() {
                unLockBlock();
            }
        });
    }

    private void uploadImage(UploadListener uploadListener) {
        try {
//            long seconds = getDuration();
            long seconds = (long) (Math.random() * 10000);
            LogUtils.i("LogTask", "uploadImage milliseconds " + seconds);
            Thread.sleep(seconds);
        } catch (Exception e) {
            e.printStackTrace();
        }
        uploadListener.onSuccess();
    }

    //任务执行完的回调，在这里你可以做些释放资源或者埋点之类的操作
    @Override
    public void finishTask() {
        super.finishTask();
        LogUtils.i("LogTask", "--finishTask-" + name);
    }
}
